;;; init-yasnippet.el --- Yasnippet configuration -*- lexical-binding: t -*-
;;; Commentray
;;; Code:

(defun get-git-user-name ()
  "Get git user name."
  (interactive)
  (replace-regexp-in-string "\n$" "" (shell-command-to-string "git config --get user.name")))

(defun get-git-user-email ()
  "Get git user email."
  (interactive)
  (replace-regexp-in-string "\n$" "" (shell-command-to-string "git config --get user.email")))

(defun ctrlwei/yas-not-active-p ()
  (not (yas-current-field)))

(dolist (hook '(prog-mode-hook
                org-mode-hook
                nxml-mode-hook))
  (add-hook hook #'yas-minor-mode))

(with-eval-after-load 'yasnippet
  (define-key yas-minor-mode-map (kbd "TAB") nil)
  (define-key yas-minor-mode-map [(tab)] nil)
  (add-hook 'yas-keymap-disable-hook #'ctrlwei/yas-not-active-p)

  (define-key yas-minor-mode-map "\C-j" #'yas-expand)
  (define-key yas-keymap "\C-j" #'yas-next-field-or-maybe-expand)

  (yas-load-directory (expand-file-name "snippets" user-emacs-directory) t))

(provide 'init-yasnippet)
;;; init-yasnippet.el ends here
